// pages/choujiang/choujiang.js
var now = new Date().getDate()
var num = Math.ceil(Math.random()*11)
var m = wx.getStorageSync('today')
    
Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    imgarr:['/pages/qiandao/qiandao','/pages/qiandao/qiandao','/pages/qiandao/qiandao','/pages/qiandao/qiandao','/pages/qiandao/qiandao','/pages/qiandao/qiandao','/pages/qiandao/qiandao','/pages/qiandao/qiandao','/pages/qiandao/qiandao','/pages/qiandao/qiandao','/pages/qiandao/qiandao','/pages/qiandao/qiandao'],
 
//这里引入你的图片链接，要对应好你的文本内容，否则会出现乱套
 
    img:'',
    isshow:0,
    shareimg:'',
    all:['0','1','2','3','4','5','6','7','8','9','10','11'],
    num2:''
  },
  select(){ 
    var m = wx.getStorageSync('today')
    var now = new Date().getDate()
        if(now!=m || m == ''){ 
          this.setData({
            img:this.data.imgarr[num],
            isshow:1,
            shareimg:this.data.imgarr[num],
            num2:this.data.all[num]
          })
          if(this.data.isshow){
            this.setData({
              display:'display:none'
            })
           wx.setStorageSync('img', this.data.imgarr[num])
           wx.setStorageSync('text', this.data.all[num])
           wx.setStorageSync('today', new Date().getDate()) 
          }     
       }
  },
  icon(){ 
    
    var m = wx.getStorageSync('today')
    var now = new Date().getDate()
    if(now!=m){
      this.setData({
        isshow:0,
        display:'display:block',
        num2:''
      })
       
    }
    if(now===m){
      wx.showToast({
        title: '请明天再来哦~',
        icon:'error',
        duration:2000
      })
    }
  },
  
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var m = wx.getStorageSync('today')
    var now = new Date().getDate()
    var img = wx.getStorageSync('img')
    var text = wx.getStorageSync('text')
// 利用缓存将此时的时间进行记录
 
    // 对时间进行判断，如果时间不同才可以继续抽签
 
    if(now===m){
      this.setData({
        img:img,
        isshow:1,
        shareimg:img,
        num2:this.data.all[text]
      })
      if(this.data.isshow){
        this.setData({
          display:'display:none'
        })
    }
  }
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var m = wx.getStorageSync('today')
    var now = new Date().getDate()
    var img = wx.getStorageSync('img')
    var text = wx.getStorageSync('text')
    
    if(now===m){
      this.setData({
        img:img,
        isshow:1,
        shareimg:img,
        num2:this.data.all[text]
      })
      if(this.data.isshow){
        this.setData({
          display:'display:none'
        })
    }
  }
  },
  /**
   * 用户点击右上角分享
   */
// 用户点击按钮即可分享
  onShareAppMessage: function (res) {
    var that = this;
    var img=that.data.img
    if (res.from === 'button') {   
        return {
          title: '今日运势',
          path: 'pages/chouqian/chouqiang',
          imageUrl:img
        }
      }   
  }
})
